package wstrader.task.warehouse.weighing;

import pc.system.*;

public class Import extends WN_IMEX
{
  public Import(Tasks owner)
  {
    //super(owner,"import","import-3",WN_IMPORT);
    super(owner,WN_IMPORT);
  }
/*
  public String getNew_WN()
  {
    return getNew_WN(getRequest().getLongValue("inst_id"));
  }
*/
/*
  public ResultSet getContract_List()
  {
    return this.getContract_List('P');
  }
*/
/*
  public ResultSet getBroker_List()
  {
    return this.getBroker_List('P');
  }
 */
  /*
  public ResultSet getDI_List()
  {
    int supplier_buyer_id = getRequest().getIntValue("supplier_buyer_id");
    String sql =
        "SELECT di.id, di.ref_number AS name, di.status " +
        "FROM delivery_instruction di " +
        "LEFT JOIN contracts ct ON di.contract_id = ct.id " +
        "WHERE (ct.supplier_buyer_id = ? OR ?) ";
    Vector vp = new Vector();
    vp.addElement(new IntValue(supplier_buyer_id));
    vp.addElement(new BooleanValue(supplier_buyer_id == 0));
    return getSQLCommand().executeQuery(sql,vp);
  }

  public ResultSet getWN_Detail()
  {
    int contract_id = getRequest().getIntValue("contract_id");
    String broker_id  = getRequest().getStringValue("broker_id","0");
    int inst_id     = getRequest().getIntValue("inst_id");
    int supplier_buyer_id = getRequest().getIntValue("supplier_buyer_id");
    int origin_id   = getRequest().getIntValue("origin_id");
    int quality_id  = getRequest().getIntValue("quality_id");
    int grade_id    = getRequest().getIntValue("grade_id");
    String sql =
        "SELECT ct.ref_number  as ct_ref_number, " +
        "       ct.contract_no," +
        "       di.ref_number as di_ref_number, " +
        "       qr.ref_number as qr_ref_number, " +
        "       wr.ref_number as wr_ref_number, " +
        "       pk.name       as packing, " +
        "       su.name       as supplier, " +
        "       wn.* " +
        "FROM weight_note_im wn " +
        "LEFT JOIN delivery_instruction di ON wn.inst_id     = di.id " +
        "LEFT JOIN contracts            ct ON di.contract_id = ct.id " +
        "LEFT JOIN warehouse_receipt    wr ON wn.wr_id       = wr.id " +
        "LEFT JOIN quality_report       qr ON wn.qr_id       = qr.id " +
        "LEFT JOIN packing_master       pk ON di.packing_id  = pk.id " +
        "LEFT JOIN company_master       su ON ct.supplier_buyer_id = su.id " +
        "WHERE (wn.inst_id           = ? OR ?) " +
        "  AND (di.contract_id       = ? OR ?) " +
        "  AND (ct.contract_no       = ? OR ?) " +
        "  AND (ct.supplier_buyer_id = ? OR ?) " +
        "  AND (ct.origin_id         = ? OR ?) " +
        "  AND (ct.quality_id        = ? OR ?) " +
        "  AND (ct.grade_id          = ? OR ?) " +
        "";
    Vector vp = new Vector();

    vp.addElement(new IntValue(inst_id));
    vp.addElement(new BooleanValue(inst_id == 0));

    vp.addElement(new IntValue(contract_id));
    vp.addElement(new BooleanValue(contract_id == 0));

    vp.addElement(new StringValue(broker_id));
    vp.addElement(new BooleanValue(broker_id.equals("0")));

    vp.addElement(new IntValue(supplier_buyer_id));
    vp.addElement(new BooleanValue(supplier_buyer_id == 0));

    vp.addElement(new IntValue(origin_id));
    vp.addElement(new BooleanValue(origin_id == 0));

    vp.addElement(new IntValue(quality_id));
    vp.addElement(new BooleanValue(quality_id == 0));

    vp.addElement(new IntValue(grade_id));
    vp.addElement(new BooleanValue(grade_id == 0));

    return getSQLCommand().executeQuery(sql,vp);
  }

  public ResultSet getWN_List()
  {
    int inst_id = getRequest().getIntValue("inst_id");
    String sql =
        "SELECT wn.id, wn.ref_number AS name, wn.status " +
        "FROM weight_note_im wn " +
        "WHERE wn.inst_id = " + inst_id + " " +
        "ORDER BY status, name DESC";
    return getSQLCommand().executeQuery(sql);
  }

  public Record getWN_Ref()
  {
    long wn_id   = getRequest().getLongValue("wn_id");
    long inst_id = getRequest().getLongValue("inst_id");
    String sql = "SELECT ";
    if (wn_id < 0) {
      sql +=
          "'" + getNew_WN() + "' AS ref_number, " +
          "      CURDATE() AS date, " +
          "      CURTIME() AS time, ";
    }
    sql +=
        "       ct.ref_number AS ct_ref_number," +
        "       ct.contract_no," +
        "       su.name AS supplier, " +
        "       og.name AS origin, " +
        "       qu.name AS quality, " +
        "       gr.name AS grade, " +
        "       pk.name AS packing, " +
        "       di.ref_number AS di_ref_number," +
        "       di.tons AS di_tons," +
        "       di.no_of_bags AS di_no_of_bags," +
        "       wn.* ";
    if (wn_id <= 0) {
      sql +=
          "FROM delivery_instruction di " +
          "LEFT JOIN weight_note_im wn  ON wn.id = 0 ";
    } else {
      sql +=
          "FROM weight_note_im wn " +
          "LEFT JOIN delivery_instruction di ON wn.inst_id     = di.id ";
    }
    sql +=
        "LEFT JOIN contracts      ct ON di.contract_id       = ct.id " +
        "LEFT JOIN packing_master pk ON di.packing_id        = pk.id " +
        "LEFT JOIN company_master su ON ct.supplier_buyer_id = su.id " +
        "LEFT JOIN origin_master  og ON ct.origin_id         = og.id " +
        "LEFT JOIN quality_master qu ON ct.quality_id        = qu.id " +
        "LEFT JOIN grade_master   gr ON ct.grade_id          = gr.id ";
    if (wn_id <= 0) {
      sql += "WHERE di.id = " + inst_id;
    }  else {
      sql += "WHERE wn.id = " + wn_id;
    }
    return new Record(getSQLCommand().executeQuery(sql));
  }

  public ResultSet getWNR_Detail()
  {
    String sql =
        "SELECT * FROM weight_note_ref WHERE wn_id = " + id;
    return getSQLCommand().executeQuery(sql);
  } */
}
